package justbuy.account.service;

import java.util.List;

import justbuy.account.model.Addressee;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.ironrhino.core.service.BaseManagerImpl;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class AddresseeManagerImpl extends BaseManagerImpl<Addressee> implements
		AddresseeManager, AddresseeService {

	@Override
	@Transactional(readOnly = true)
	public Addressee findPrimaryByUserId(String userId) {
		DetachedCriteria dc = detachedCriteria();
		dc.add(Restrictions.eq("userId", userId));
		dc.add(Restrictions.eq("primary", Boolean.TRUE));
		return findByCriteria(dc);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Addressee> findByUserId(String userId) {
		DetachedCriteria dc = detachedCriteria();
		dc.add(Restrictions.eq("userId", userId));
		return findListByCriteria(dc);
	}

}
